<?php


namespace app\admin\controller\ter;

use app\api\controller\Order;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;
use think\facade\Env;

/**
 * @ControllerAnnotation(title="技师审核列表")
 */
class TechnicianReview extends AdminController
{

    use \app\admin\traits\Curd;
    protected $sort = [
        'id'   => 'desc',
    ];

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new \app\admin\model\TechnicianReview();
        
    }
    
    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select();
            // foreach ($list as $k => $v){
            //     //service_gid
            //     $service_goods = Db::name("service_goods")->where("id",$v["service_gid"])->find();
            //     $v['service_name'] = $service_goods['title'];
            //     $v['service_img'] = $service_goods['zhu_img'];
            //     $list[$k] = $v;
            // }
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }
    
     

    /**
    * @NodeAnotation(title="通过")
    */
    public function adopt_url()
    {
        if ($this->request->isAjax()) {
            $post = $this->request->param();
            $ret = $this->model->where('id', $post['id'])->where('status', 0)->find();
            if (empty($ret)) {
                $this->error('当前状态不能审核');
            }
            Db::name("technician_review")->where("id",$post["id"])->update(["status"=>1]);
            //新增技师表数据
            $tdata = [
                "service_name"=>$ret["username"],
                "phone"=>$ret["phone"],
                "service_img"=>$ret["img"],
                "sex"=>$ret["sex"],
                "age"=>$ret["age"],
                "uid"=>$ret["uid"],
                "create_time"=>time()

            ];
            Db::name("service_technician")->insert($tdata);
            $this->success('操作成功', '');
        }
        return $this->fetch();
    }

  

      /**
    * @NodeAnotation(title="驳回")
    */
    public function reject_url()
    {
        if ($this->request->isAjax()) {
            $post = $this->request->param();
            $ret = $this->model->where('id', $post['id'])->where('status', 0)->find();
            if (empty($ret)) {
                $this->error('当前状态不能审核');
            }
            if(empty($post["reason_for_rejection"])){
                $this->error("驳回原因不能为空");
            }
            Db::name("technician_review")->where("id",$post["id"])->update(["status"=>2,"rejection"=>$post["reason_for_rejection"]]);
            $this->success('驳回成功', '');
        }
        return $this->fetch();
    }

    
 
} 